package com.view.commonView.validation.impl;

import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JTextField;

import com.util.Validator;
import com.view.commonView.IconSrc;
import com.view.commonView.validation.AbstractValidator;

/**
 * A class for performing basic validation on text fields. All it does is make
 * sure that they are not null.
 * 
 * @author Diego Iacono
 */
public class EmailValidator extends AbstractValidator {
   
   private String message = null;
   
   /**
    * Constructor Empty Validator
    * @param JFrame parent
    * @param c
    */
   public EmailValidator(JFrame parent, JTextField c)
   {
      super(parent, c, null);
   }

   /**
    * Constructor Empty Validator
    * @param JFrame parent
    * @param c
    */
   public EmailValidator(JDialog parent, JTextField c)
   {
      super(parent, c, null);
   }

   /* (non-Javadoc)
    * @see com.view.commonView.validation.AbstractValidator#validationCriteria(javax.swing.JComponent)
    */
   protected boolean validationCriteria(JComponent c)
   {
      String value = ((JTextField) c).getText();
      message = Validator.validateEmailFormat(value);
      this.setMessage(message);
      this.setIcon(IconSrc.POPUP_HELP_EXCLAMATION);
      if (Validator.isNullOrEmpty(message))
      {
         return true;
      }
      return false;
   }
}
